﻿using System;
using System.Drawing;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace SenseTimeTracker.Reports
{
	public class UtilisationDisplayItem : CommonSenseControls.CommonSenseDisplayPanelItem
	{
		private string label;
    private float utilisationLimit;
		private float utilisationCurrent;

		public UtilisationDisplayItem()
		{
			Height = 50;
		}

		public string Label
		{
			get { return label; }
			set { label = value; }
		}

		public float UtilisationLimit
		{
			get { return utilisationLimit; }
			set { utilisationLimit = value; }
		}

		public float UtilisationCurrent
		{
			get { return utilisationCurrent; }
			set { utilisationCurrent = value; }
		}

		#region ISenseListItem Members

		public override void OnRender(Graphics g)
		{
			using (Brush blackBrush = new SolidBrush(Color.Black))
			using (Brush redBrush = new SolidBrush(Color.Red))
			using (Font primaryFont = new Font("Helvetica Neue OTS", 9f, FontStyle.Regular))
			using (Font secondaryFont = new Font("Helvetica Neue OTS", 7f, FontStyle.Regular))
			{
				SizeF labelTextSize = g.MeasureString(label, primaryFont);
				g.DrawString(label, primaryFont, blackBrush, ClientRectangle.Left + 8, ClientRectangle.Top + ClientRectangle.Height * 1 / 4 - labelTextSize.Height / 2 + 4);
				string utilisationCurrentString = string.Format("{0:0.00}", utilisationCurrent);
				SizeF utilisationCurrentTextSize = g.MeasureString(utilisationCurrentString, secondaryFont);
				g.DrawString(utilisationCurrentString, secondaryFont, utilisationCurrent <= utilisationLimit ? blackBrush : redBrush, ClientRectangle.Left + ClientRectangle.Width * 3 / 4 - utilisationCurrentTextSize.Width - 8, ClientRectangle.Top + ClientRectangle.Height * 3 / 4 - labelTextSize.Height / 2 - 4);
				string utilisationLimitString = string.Format("{0:0.00}", utilisationLimit);
				SizeF utilisationLimitTextSize = g.MeasureString(utilisationLimitString, secondaryFont);
				g.DrawString(utilisationLimitString, secondaryFont, blackBrush, ClientRectangle.Right - 8 - utilisationLimitTextSize.Width, ClientRectangle.Top + ClientRectangle.Height * 3 / 4 - labelTextSize.Height / 2 - 4);
			}

			base.OnRender(g);
		}
		#endregion
	}
}
